Skip to content

refactor!: enforce strict types, fix API bugs, and add WebSocket builder pattern#32

Merged
parsilver merged 4 commits intomainfrom
refactor/code-quality-and-fixes
Mar 2, 2026
Merged

refactor!: enforce strict types, fix API bugs, and add WebSocket builder pattern#32
parsilver merged 4 commits intomainfrom
refactor/code-quality-and-fixes

Conversation

@parsilver
Copy link
Contributor

@parsilver parsilver commented Mar 2, 2026

Summary

Major quality and reliability overhaul for the Bitkub PHP SDK — enforces strict typing across all files, fixes several API and data-handling bugs, refactors the WebSocket client with a builder pattern, and significantly expands test coverage.

Breaking Changes

  • Message class is now immutableoffsetSet, offsetUnset, __set, and __unset throw BadMethodCallException
  • PendingRequest properties changed from public to private — use accessor methods instead
  • WebSocketClient constructor signature changed — accepts engine and optional HTTP client; use WebSocketClientBuilder for configuration
  • LiveOrderBookEndpoint symbol map is now an instance property instead of static

Bug Fixes

  • Fix array_filter usage with explicit callbacks to prevent filtering out valid falsy values (e.g., 0)
  • Fix my-open-orders endpoint to send sym as query param instead of request body (matches Bitkub API v3 spec)
  • Fix BitkubResponseErrorCodeException to handle missing error codes gracefully instead of throwing raw exceptions
  • Replace @json_decode with proper validation (is_array checks)
  • Fix README typos and incorrect API path for wallet endpoint (GETPOST /api/v3/market/wallet)

Improvements

  • Add declare(strict_types=1) and return type declarations across all PHP files
  • Cache endpoint instances, server timestamp drift, and symbol map to reduce redundant HTTP calls
  • Add WebSocketClientBuilder for fluent WebSocket client configuration
  • Add reconnection logic with configurable attempts to WebSocket Engine
  • Improve WebSocket stream name validation with regex
  • Improve type hints and PHPDoc annotations across WebSocket components

CI/CD

  • Restrict code style workflow to main branch only
  • Fix dependabot auto-merge workflow trigger (pull_request_targetpull_request)
  • Set minimum-stability to stable in composer.json

Documentation

  • Fix WebSocket examples to use WebSocketClientBuilder
  • Add LiveOrderBook endpoint documentation
  • Add PHP 8.2+ requirement badge to README

Tests

  • Add tests for GenerateSignatureV3 (header attachment, timestamp caching, HMAC computation)
  • Add tests for market order endpoints (openOrders, myOrderHistory, myOrderInfo)
  • Add tests for immutable Message behavior and ResponseWithValidateErrorCode custom callbacks
  • Add MockHttpClient request recording for better test assertions
  • Add MockWebSocketEngine and tests for Engine, endpoints, and builder
  • Refactor existing WebSocket tests to use mock engine

Test Plan

  • Run composer test — all existing and new tests pass
  • Verify GenerateSignatureV3 timestamp caching reduces server time API calls
  • Verify Message immutability throws BadMethodCallException on mutation
  • Verify array_filter fix preserves valid falsy values (e.g., 0)
  • Verify my-open-orders sends sym as query param (not body)
  • Verify WebSocketClientBuilder produces correctly configured clients

- Add declare(strict_types=1) and return type declarations across all PHP files
- Fix array_filter usage with explicit callbacks to prevent filtering falsy values like 0
- Fix my-open-orders endpoint to use query params instead of request body
- Cache endpoint instances, server timestamp drift, and symbol map for performance
- Make Message class immutable (throw on set/unset operations)
- Fix BitkubResponseErrorCodeException to handle missing error codes gracefully
- Replace @json_decode with proper validation
- Improve stream name validation with regex in WebSocket MarketEndpoint
- Change PendingRequest properties from public to private
- Restrict code style CI to main branch, fix dependabot workflow trigger
- Set minimum-stability to stable in composer.json
- Fix README typos and incorrect API path for wallet endpoint
- Add tests for GenerateSignatureV3, market order endpoints, and immutable Message
- Add request recording to MockHttpClient for better test assertions
@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

❌ Patch coverage is 78.14208% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.20%. Comparing base (38266cc) to head (ab0e4e3).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/WebSocket/Engine.php 0.00% 40 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main      #32      +/-   ##
============================================
+ Coverage     82.36%   89.20%   +6.84%     
- Complexity      155      180      +25     
============================================
  Files            21       22       +1     
  Lines           482      556      +74     
============================================
+ Hits            397      496      +99     
+ Misses           85       60      -25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Refactor WebSocketClient to accept engine and optional client via constructor
- Add WebSocketClientBuilder for fluent WebSocket client configuration
- Convert LiveOrderBookEndpoint symbol map from static to instance property
- Add reconnection logic with configurable attempts to WebSocket Engine
- Improve type hints and PHPDoc annotations across WebSocket components
- Add MockWebSocketEngine and dedicated tests for Engine, endpoints, and builder
…ment

- Fix WebSocket examples to use WebSocketClientBuilder instead of direct instantiation
- Add documentation for LiveOrderBook endpoint
- Add PHP 8.2+ requirement to README header
- Add WebSocket section to table of contents
@parsilver parsilver changed the title Improve code quality, fix bugs, and add strict typing refactor!: enforce strict types, fix API bugs, and add WebSocket builder pattern Mar 2, 2026
- Fix TypeError in Message::json($key) when called on invalid JSON body
- Add tests for filterParams, GenerateSignatureV3, error codes, URI factory,
  PendingRequest send/interceptors, PSR-7 decorator delegation, lazy singletons,
  WebSocket client/builder edge cases, and market/orderbook endpoints
@parsilver parsilver merged commit 7831c30 into main Mar 2, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant